package 模式匹配;

public class PatternDemo {
    public static void matchByJDK8(Object value){
        if(value instanceof String){
            String v= (String) value;
            System.out.println("String类型："+v);
        }else if(value instanceof Integer){
            Integer v=(Integer) value;
            System.out.println("Integer类型："+v.longValue());
        }else{
            System.out.println("waining");
        }
    }

    public static void matchByJDK17(Object value){
        if(value instanceof String v){
            System.out.println("String类型："+v);
        }else if(value instanceof Integer v){
            System.out.println("Integer类型："+ v);
        }else{
            System.out.println("warning");
        }
    }


    public static void main(String[] args) {
        String s="hello";
        Integer i=20000;
        Double d=2.45;
        matchByJDK8(s);
        matchByJDK17(s);
        matchByJDK8(i);
        matchByJDK17(i);
        matchByJDK17(d);
    }
}
